package com.liangxy.zhyl.controller;

import com.liangxy.zhyl.base.PageResponse;
import com.liangxy.zhyl.base.ResponseResult;
import com.liangxy.zhyl.dto.NursingPlanDto;
import com.liangxy.zhyl.dto.NursingProjectPlanDto;
import com.liangxy.zhyl.service.NursingPlanService;
import com.liangxy.zhyl.vo.NursingPlanVo;
import com.liangxy.zhyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {

    @Autowired
     private NursingPlanService nursingPlanService;

    /**
     * 查询所有的护理计划
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有的护理计划")
    public ResponseResult<NursingPlanDto> nursingPlanList(){
        List<NursingProjectVo> nursingProjectVo = nursingPlanService.selectAll();
        return ResponseResult.success(nursingProjectVo);
    }
    @PostMapping
    @ApiOperation("添加护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingProjectPlanDto nursingProjectPlanDto){
        nursingPlanService.addNursingPlan(nursingProjectPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> selectNursingPlan(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.selectNursingPlan(id);
        return ResponseResult.success(nursingPlanVo);
    }
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>>
    pageNursingPlan(@RequestParam(required = false) String planName,  // 护理计划名称
                    @RequestParam(required = false) Integer status,  //  状态 ： 0 禁用；1 启用
                    @RequestParam(defaultValue = "10" ) Integer pageSize,  // 每页数量
                    @RequestParam(defaultValue = "1", required = false) Integer pageNum){
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.pageNursingPlan(planName, status, pageSize, pageNum);
        return ResponseResult.success(pageResponse);
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("禁用启用护理计划")
    public ResponseResult updateNursingPlanStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingPlanService.updateNursingPlanStatus(id, status);
        return ResponseResult.success();
    }
    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateNursingPlan(@PathVariable Long id, @RequestBody NursingProjectPlanDto nursingProjectPlanDto){
        nursingPlanService.updateNursingPlan(id, nursingProjectPlanDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Long id){
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }
}
